package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "用户系统所用的医院控制层")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "根据排班id查询排班详情")
    @GetMapping("getSchedule/{id}")
    public R getScheduleList(
            @PathVariable(value = "id") String scheduleId) {
        Schedule schedule = scheduleService.getScheduleInfo(scheduleId);
        return R.ok().data("schedule",schedule);
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList",scheduleList);
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {
        Map<String,Object> map =scheduleService.getBookingSchedule(page,limit,hoscode,depcode);
        return R.ok().data(map);
    }

    @ApiOperation(value = "根据医院编号，查询医院信息")
    @GetMapping("/info/{hoscode}")
    public R info(@PathVariable(value = "hoscode") String hoscode){
        Hospital byHoscode = hospitalService.findByHoscode(hoscode);
        return R.ok().data("hospital",byHoscode);
    }

    @ApiOperation(value = "根据医院编号，查询医院底下所有科室信息，大科室嵌套小科室")
    @GetMapping("/department/list/{hoscode}")
    public R getDepartmentListByHoscode(@PathVariable(value = "hoscode") String hoscode){
        List<DepartmentVo> allDepts = departmentService.getAllDepts(hoscode);
        return R.ok().data("list",allDepts);
    }

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public R index(
            @PathVariable(value = "page") Integer page,
            @PathVariable(value = "limit") Integer limit,
            HospitalQueryVo hospitalQueryVo) {

        Page<Hospital> pageModel = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return R.ok().data("pages",pageModel);
    }

    @ApiOperation(value = "根据医院名称进行模糊查询，查询个所有的符号条件的医院")
    @GetMapping("/findByNameLike/{name}")
    public R findByNameLike(
            @PathVariable(value = "name") String name
            ) {
        List<Hospital> hospitals=  hospitalService.findByNameLike(name);
        return R.ok().data("list",hospitals);
    }
}